from datetime import datetime

from django.db import models

from apps.maps.models import Map


class Play(models.Model):
    """
    播放视频模型
    """

    map = models.OneToOneField(Map, on_delete=models.DO_NOTHING, verbose_name='所属设备')
    video = models.CharField(max_length=1000, default='', verbose_name='监控直播地址')
    monitor_id = models.CharField(max_length=100, verbose_name='播放直播流id')
    add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

    class Meta:
        verbose_name = '播放视频管理'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.monitor_id


class Video(models.Model):
    """
    播放录像模型
    """
    map = models.OneToOneField(Map, on_delete=models.DO_NOTHING, verbose_name='所属设备')
    video = models.CharField(max_length=1000, default='', verbose_name='监控录像地址')
    monitor_id = models.CharField(max_length=100, verbose_name='播放录像id')
    add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

    class Meta:
        verbose_name = '播放录像管理'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.monitor_id


class Warn_model(models.Model):
    # TYPE_CHOICES = ((1, '智能预警'), (2, '手动预警'))
    image_id = models.CharField(default='',verbose_name='图片id',max_length=300)
    name = models.CharField(default='监控点', max_length=300, verbose_name='监控名称')
    image = models.ImageField(upload_to='images', verbose_name='图片内容')
    ip = models.CharField(max_length=300, default='', verbose_name='ip地址')  # Pillow
    type = models.CharField(max_length=300, default='', verbose_name='预警类型')
    add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')
    # a = models.IntegerField(default=1, choices=TYPE_CHOICES, verbose_name='预警类型')

    class Meta:
        verbose_name = '预警数据'

    def __str__(self):
        return self.ip